package operators;

public class ArithmeticOperators {
    public static void main(String[] args) {
        int a = 10;
        int b = 3;

        // 基本算术运算
        int sum = a + b;          // 加法: 13
        int difference = a - b;   // 减法: 7
        int product = a * b;      // 乘法: 30
        int quotient = a / b;     // 除法: 3（整数除法会截断小数部分）
        int remainder = a % b;    // 取余/模运算: 1

        System.out.println("a + b = " + sum);
        System.out.println("a - b = " + difference);
        System.out.println("a * b = " + product);
        System.out.println("a / b = " + quotient);
        System.out.println("a % b = " + remainder);

        // 自增自减运算符
        int c = 5;
        c++;  // 等价于 c = c + 1，先使用后加1
        System.out.println("c++ = " + c);  // 输出6

        int d = 5;
        ++d;  // 等价于 d = d + 1，先加1后使用
        System.out.println("++d = " + d);  // 输出6

        int e = 5;
        int f = e++;  // f得到e的原始值5，然后e变为6
        System.out.println("e = " + e + ", f = " + f);  // 输出e = 6, f = 5

        int g = 5;
        int h = ++g;  // g先变为6，然后h得到6
        System.out.println("g = " + g + ", h = " + h);  // 输出g = 6, h = 6
    }
}
